package com.nowcoder.community.util;

public class RedisKeyUtil {

    private static final String SPLIT = ":";
    private static final String PREFIX_ENTITY_LIKE = "like:entity";
    private static final String PREFIX_USER_LIKE = "like:user";
    private static final String PREFIX_FOLLOWEE = "followee";
    private static final String PREFIX_FOLLOWER = "follower";


//    生成某个实体的赞
//    like:entity:entityType:entityId -> set(userId)，保存点赞的用户的id，
//    要求赞的数目只要获取set的size即可
    public static String getEntityLikeKey(int entityType, int entityKey) {
        return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityKey;
    }

//    某个用户的赞
    public static String getUserLikeKey(int userId){
        return PREFIX_USER_LIKE + SPLIT + userId;
    }

//    某个用户关注的实体
//    followee:userId:entityType -> zset(entityId, now)
    public static String getFolloweeKey(int userId, int entityType){
        return PREFIX_FOLLOWEE + SPLIT + userId + SPLIT + entityType;
    }

//    某个实体拥有的粉丝
//    follower:entityType:entityId -> zset(userId,now)
    public static String getFollowerKey(int entityId, int entityType){
        return PREFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
    }
}
